
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>Kubernetes Nodes · GitBook笔记</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="chenjiebin">
        
        
    
    <link rel="stylesheet" href="../../../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../../../gitbook/gitbook-plugin-prism/prism.css">
                
            
                
                <link rel="stylesheet" href="../../../../gitbook/gitbook-plugin-search-pro/search.css">
                
            
                
                <link rel="stylesheet" href="../../../../gitbook/gitbook-plugin-expandable-chapters-small/expandable-chapters-small.css">
                
            
                
                <link rel="stylesheet" href="../../../../gitbook/gitbook-plugin-splitter/splitter.css">
                
            
                
                <link rel="stylesheet" href="../../../../gitbook/gitbook-plugin-anchor-navigation-ex/style/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../../../gitbook/gitbook-plugin-code/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="../kubernetes.html" />
    
    
    <link rel="prev" href="components.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../../../">
            
                <a href="../../../../">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../kubernetes.html">
            
                <a href="../kubernetes.html">
            
                    
                    Kubernetes英文教程
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../kubernetes.html">
            
                <a href="../kubernetes.html#concepts">
            
                    
                    Kubernetes Concepts
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1.1" data-path="overview.html">
            
                <a href="overview.html">
            
                    
                    Kubernetes Overview
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.1.2" data-path="components.html">
            
                <a href="components.html">
            
                    
                    Kubernetes Components
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.2.1.3" data-path="nodes.html">
            
                <a href="nodes.html">
            
                    
                    Kubernetes Nodes
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="../kubernetes.html">
            
                <a href="../kubernetes.html#tutorial">
            
                    
                    Kubernetes Tutorial
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.2.1" data-path="../tutorial/kubernetes-basics.html">
            
                <a href="../tutorial/kubernetes-basics.html">
            
                    
                    Kubernetes Basics
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../../../java/java.html">
            
                <a href="../../../java/java.html">
            
                    
                    Java基础知识
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../../../java/java-summary.html">
            
                <a href="../../../java/java-summary.html">
            
                    
                    Java_Summary
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="../../../java/java-jvm.html">
            
                <a href="../../../java/java-jvm.html">
            
                    
                    Java_JVM
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="../../../java/effectiveJava.html">
            
                <a href="../../../java/effectiveJava.html">
            
                    
                    effectiveJava
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="../../../java/design-pattern.html">
            
                <a href="../../../java/design-pattern.html">
            
                    
                    设计模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.5" data-path="../../../java/JavaTest.html">
            
                <a href="../../../java/JavaTest.html">
            
                    
                    JavaTest
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.6" data-path="../../../java/myframe.html">
            
                <a href="../../../java/myframe.html">
            
                    
                    MyFrame
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../../../database/database.html">
            
                <a href="../../../database/database.html">
            
                    
                    数据库基础知识
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../../../database/mysql.html">
            
                <a href="../../../database/mysql.html">
            
                    
                    MySQL
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="../../../database/redis.html">
            
                <a href="../../../database/redis.html">
            
                    
                    Redis
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="../../../database/kingbase.html">
            
                <a href="../../../database/kingbase.html">
            
                    
                    KingBase
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4" data-path="../../../database/polardb.html">
            
                <a href="../../../database/polardb.html">
            
                    
                    PolarDB
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../../../system/system.html">
            
                <a href="../../../system/system.html">
            
                    
                    环境配置工具
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="../../../system/nodejs.html">
            
                <a href="../../../system/nodejs.html">
            
                    
                    Node.js
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="../../../system/gitbook.html">
            
                <a href="../../../system/gitbook.html">
            
                    
                    Gitbook
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="../../../system/linux.html">
            
                <a href="../../../system/linux.html">
            
                    
                    Linux
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.4" data-path="../../../system/kylin.html">
            
                <a href="../../../system/kylin.html">
            
                    
                    麒麟系统
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="../../../tool/tool.html">
            
                <a href="../../../tool/tool.html">
            
                    
                    开发工具介绍
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="../../../tool/docker.html">
            
                <a href="../../../tool/docker.html">
            
                    
                    Docker
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="../../../tool/idea.html">
            
                <a href="../../../tool/idea.html">
            
                    
                    Idea
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.3" data-path="../../../tool/maven.html">
            
                <a href="../../../tool/maven.html">
            
                    
                    Maven
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.4" data-path="../../../tool/gradle.html">
            
                <a href="../../../tool/gradle.html">
            
                    
                    Gradle
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.5" data-path="../../../framework/kubernate.html">
            
                <a href="../../../framework/kubernate.html">
            
                    
                    Kubernetes
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../../../.." >Kubernetes Nodes</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <div id="anchor-navigation-ex-navbar"><i class="fa fa-navicon"></i><ul><li><span class="title-icon "></span><a href="#nodes"><b>1. </b>Nodes</a></li><ul><li><span class="title-icon "></span><a href="#management"><b>1.1. </b>Management</a></li><ul><li><span class="title-icon "></span><a href="#node-name-uniqueness"><b>1.1.1. </b>Node name uniqueness</a></li><li><span class="title-icon "></span><a href="#self-registration-of-nodes"><b>1.1.2. </b>Self-registration of Nodes</a></li><li><span class="title-icon "></span><a href="#manual-node-administration"><b>1.1.3. </b>Manual Node administration</a></li></ul><li><span class="title-icon "></span><a href="#node-status"><b>1.2. </b>Node status</a></li><li><span class="title-icon "></span><a href="#node-heartbeats"><b>1.3. </b>Node heartbeats</a></li><li><span class="title-icon "></span><a href="#node-controller"><b>1.4. </b>Node controller</a></li><ul><li><span class="title-icon "></span><a href="#rate-limits-on-eviction"><b>1.4.1. </b>Rate limits on eviction</a></li></ul><li><span class="title-icon "></span><a href="#resource-capacity-tracking"><b>1.5. </b>Resource capacity tracking</a></li><li><span class="title-icon "></span><a href="#node-topology"><b>1.6. </b>Node topology</a></li><li><span class="title-icon "></span><a href="#graceful-nodes-shutdown"><b>1.7. </b>Graceful nodes shutdown</a></li><ul><li><span class="title-icon "></span><a href="#pod-priority-based-graceful-nodes-shutdown"><b>1.7.1. </b>Pod priority based graceful nodes shutdown</a></li></ul><li><span class="title-icon "></span><a href="#non-graceful-nodes-shutdown-handling"><b>1.8. </b>Non-graceful nodes shutdown handling</a></li><li><span class="title-icon "></span><a href="#swap-memory-management"><b>1.9. </b>Swap memory management</a></li><li><span class="title-icon "></span><a href="#whats-next"><b>1.10. </b>What&apos;s next</a></li></ul></ul></div><a href="#nodes" id="anchorNavigationExGoTop"><i class="fa fa-arrow-up"></i></a><h1 id="nodes"><a name="nodes" class="anchor-navigation-ex-anchor" href="#nodes"><i class="fa fa-link" aria-hidden="true"></i></a>1. Nodes</h1>
<p>Kubernetes runs your workload by placing containers into Pods to run on Nodes.
A node may be a virtual or physical machine, depending on the cluster. Each node is managed by
the control plane and contains the services necessary to run Pods.</p>
<p>Typically, you have several nodes in cluster; in a learning or resource-limited environment,
you might have only one node.</p>
<p>The components on a node include the kubelet, a container runtime, and the kube-proxy.</p>
<h2 id="management"><a name="management" class="anchor-navigation-ex-anchor" href="#management"><i class="fa fa-link" aria-hidden="true"></i></a>1.1. Management</h2>
<p>There are two main ways to have Nodes added to the API server:</p>
<ol>
<li>The kubelet on a node self-registers to the control plane</li>
<li>You (or another human user) manually add a Node object</li>
</ol>
<p>After you create a Node object, or the kubelet on a node self-registers, the control plane
checks whether the new Node object is valid. For example, if you try to create a Node from
the following JSON manifest:</p>
<pre class="language-"><code class="lang-json"><span class="token punctuation">{</span>
  <span class="token property">&quot;kind&quot;</span><span class="token operator">:</span> <span class="token string">&quot;Node&quot;</span><span class="token punctuation">,</span>
  <span class="token property">&quot;apiVersion&quot;</span><span class="token operator">:</span> <span class="token string">&quot;v1&quot;</span><span class="token punctuation">,</span>
  <span class="token property">&quot;metadata&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
    <span class="token property">&quot;name&quot;</span><span class="token operator">:</span> <span class="token string">&quot;10.240.79.157&quot;</span><span class="token punctuation">,</span>
    <span class="token property">&quot;labels&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
      <span class="token property">&quot;name&quot;</span><span class="token operator">:</span> <span class="token string">&quot;my-first-k8s-node&quot;</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
<p>Kubernetes creates a Node object internally (the representation). Kubernetes checks that a kubelet
has registered to the API server that matches the <code>metadata.name</code> field of the Node. If the node
is healthy (i.e. all necessary services are running), then it is eligible to run a Pod. Otherwise,
that node is ignored for any cluster activity until it becomes healthy.</p>
<p>The name of a Node object must be a valid DNS subdomain name.</p>
<h3 id="node-name-uniqueness"><a name="node-name-uniqueness" class="anchor-navigation-ex-anchor" href="#node-name-uniqueness"><i class="fa fa-link" aria-hidden="true"></i></a>1.1.1. Node name uniqueness</h3>
<p>The name identifies a Node. Two Nodes cannot have the same name at the same time. Kubernetes also
assumes that a resource with the same name is the same object. In case of Node, it is implicitly
assumed that an instance using the same name will have the same state (e.g. network settings, root
disk contents) and attributes like node labels. This may lead to inconsistencies if an instance was
modified without changing its name. If the Node needs to be replaced or updated significantly, the
existing Node object needs to be removed from API server first and re-added after the update.</p>
<h3 id="self-registration-of-nodes"><a name="self-registration-of-nodes" class="anchor-navigation-ex-anchor" href="#self-registration-of-nodes"><i class="fa fa-link" aria-hidden="true"></i></a>1.1.2. Self-registration of Nodes</h3>
<p>When the kubelet flag <code>--register-node</code> is true (the default), the kubelet will attempt to register
itself with the API server. This is the preferred pattern, used by most distros.</p>
<p>For self-registration, the kubelet is started with the following options:</p>
<ul>
<li><code>--kubeconfig</code> Path to credentials to authenticate itself to the API server.</li>
<li><code>--cloud-provider</code> How to talk to a cloud provider to read metadata about itself.</li>
<li><code>--register-node</code> Automatically register with the API server.</li>
<li><code>--register-with-taints</code> Register the node with given list of taints</li>
<li><code>--node-ip</code> Optional comma-separated list of the IP addresses for the node. You can only specify
a single address for each address family. For example, in a single-stack IPv4 cluster, you set
this value to be the IPv4 address that the kubelet should use for the node.
If you don&apos;t provide this argument, the kubelet uses the node&apos;s default IPv4 address, if nay;
if the node has no IPv4 addresses then the kubelet uses the node&apos;s default IPv6 address.</li>
<li><code>--node-labels</code> Labels to add when registering the node in the cluster</li>
<li><code>--node-status-update-frequency</code> Specifies how often kubelet posts its node status to the API server.</li>
</ul>
<p>When the Node authorization mode and NodeRestriction admission plugin are enabled, kubelets are only
authorized to create/modify their own Node resource.</p>
<h3 id="manual-node-administration"><a name="manual-node-administration" class="anchor-navigation-ex-anchor" href="#manual-node-administration"><i class="fa fa-link" aria-hidden="true"></i></a>1.1.3. Manual Node administration</h3>
<p>You can create and modify Node objects using kubectl.</p>
<p>When you want to create Node objects manually, set the kubelet flag <code>--register-node-false</code></p>
<p>You can modify Node objects regardless of the setting of <code>--register-node</code>. For example, you can
set labels on an existing Node or mark it unschedulable.</p>
<p>You can use labels on Nodes in conjunction with node selectors on Pods to control scheduling. For
example, you can constrain a Pod to only be eligible to run on a subset of the available nodes.</p>
<p>Marking a node as unschedulable prevents the scheduler from placing new pods onto that Node but does
not affect existing Pods on the Node. This is useful as a preparatory step before a node reboot or
other maintenance.</p>
<p>To mark a Node unschedulable, run:</p>
<pre class="language-"><code class="lang-bash">kubectl cordon <span class="token operator">&amp;</span>NODENAME
</code></pre>
<h2 id="node-status"><a name="node-status" class="anchor-navigation-ex-anchor" href="#node-status"><i class="fa fa-link" aria-hidden="true"></i></a>1.2. Node status</h2>
<p>A Node&apos;s status contains the following information:</p>
<ul>
<li>Addresses</li>
<li>Conditions</li>
<li>Capacity and Allocatable</li>
<li>Info</li>
</ul>
<p>You can use <code>kubectl</code> to view a Node&apos;s status and other details:</p>
<pre class="language-"><code class="lang-bash">kubectl describe <span class="token function">node</span> <span class="token operator">&lt;</span>insert-node-name-here<span class="token operator">&gt;</span>
</code></pre>
<h2 id="node-heartbeats"><a name="node-heartbeats" class="anchor-navigation-ex-anchor" href="#node-heartbeats"><i class="fa fa-link" aria-hidden="true"></i></a>1.3. Node heartbeats</h2>
<p>Heartbeats, sent by Kubernetes nodes, help your cluster determine the availability of each node,
and to take action when failures are detected.</p>
<p>For nodes there are two forms of heartbeats:</p>
<ul>
<li>Updates to the <code>state</code> of a Node.</li>
<li>Lease objects within the <code>kube-node-lease</code> namespace. Each Node has an associated Lease object.</li>
</ul>
<h2 id="node-controller"><a name="node-controller" class="anchor-navigation-ex-anchor" href="#node-controller"><i class="fa fa-link" aria-hidden="true"></i></a>1.4. Node controller</h2>
<p>The node controller is a Kubernetes control plane component that manages various aspects of nodes.</p>
<p>The node controller has multiple roles in a node&apos;s life. The first is assigning a CIDR block to the
node when it is registered (if CIDR assignment is turned on).</p>
<p>The second is keeping the node controller&apos;s internal list of nodes up to date with the cloud provider&apos;s
list of available machines. When running in a cloud environment and whenever a node is unhealthy, the 
node controller asks the cloud provider if the VM for that node is still available. If not, the node
controller deletes the onde from its list of nodes.</p>
<p>The third is monitoring the node&apos;s health. The node controller is responsible for:</p>
<ul>
<li>In the case that a node becomes unreachable, updating the <code>Ready</code> condition in the Node&apos;s <code>status</code>
field. In this case the node controller sets the <code>Ready</code> condition to <code>Unknown</code>.</li>
<li>If a node remains unreachable: triggering API-initiated eviction for all the Pods on the
unreachable node. By default, the node controller waits 5 minutes between marking the nodes
as <code>Unknown</code> and submitting the first eviction request.</li>
</ul>
<p>By default, the node controller checks the state of each node every 5 seconds. This period can be
configured using the <code>--node-monitor-period</code> flag on the <code>kube-controller-manager</code> component.</p>
<h3 id="rate-limits-on-eviction"><a name="rate-limits-on-eviction" class="anchor-navigation-ex-anchor" href="#rate-limits-on-eviction"><i class="fa fa-link" aria-hidden="true"></i></a>1.4.1. Rate limits on eviction</h3>
<p>In most cases, the node controller limits the eviction rate to <code>node-eviction-rate</code> (default 0.1)
per second, meaning it won&apos;t evict pods from more than 1 node per 10 seconds.</p>
<p>The node eviction behavior changes when a node in a given availability zone becomes unhealthy.
The node controller checks what percentage of nodes in the zone are unhealthy ( the <code>Ready</code>
condition is <code>Unknown</code> or <code>False</code>) at the same time:</p>
<ul>
<li>If the fraction of unhealthy nodes is at least <code>--unhealthy-zone-threshold</code> (default 0.55),
then the eviction rate is reduced.</li>
<li>If the cluster is small (i.e. has less than or equal to <code>--large-cluster-size-threshold</code> nodes 
default 50), then evictions are stopped.</li>
<li>Otherwise, the eviction rate is reduced to <code>--secondary-node-eviction-rate</code> (default 0.01)
per second.</li>
</ul>
<p>The reason these policies are implemented per availability zone is because one availability zone
might become partitioned from the control plane while the others remain connected. If your cluster
does not span multiple cloud provider availability zones, then the eviction mechanism does not take
per-zone unavailability into account.</p>
<p>A key reason for spreading your nodes across availability zones is so that the workload can be shifted
to healthy zones when on entire zone goes down. Therefore, if all nodes in a zone are unhealthy, then
the node controller evicts at the normal rate of <code>--node-eviction-rate</code>. The corner case is when all
zones are completely unhealthy (none of the nodes in the cluster are healthy). In such a case, the node
controller assumes that there is some problem with connectivity between the control plane and the
nodes, and doesn&apos;t perform any evictions. (If there has been an outage and some nodes reappear, the
node controller does evict pods from the remaining nodes that are unhealthy or unreachable).</p>
<p>The node controller is also responsible for evicting pods running on nodes with <code>NoExecute</code> taints,
unless those pods tolerate that taint. The node controller also adds taints corresponding to node
problems like node unreachable or not ready. This means that the scheduler won&apos;t place Pods onto
unhealthy nodes.</p>
<h2 id="resource-capacity-tracking"><a name="resource-capacity-tracking" class="anchor-navigation-ex-anchor" href="#resource-capacity-tracking"><i class="fa fa-link" aria-hidden="true"></i></a>1.5. Resource capacity tracking</h2>
<p>Node objects track information about the Node&apos;s resource capacity: for example, the amount of memory
available and the number of CPUs. Nodes that self register report their capacity during registration.
If you manually add a Node, then you need to set the node&apos;s capacity information when you add it.</p>
<p>The Kubernetes scheduler ensures that there are enough resources for all the Pods on a Node. The
scheduler checks that the sum of the requests of containers on the node is no greater than the node&apos;s
capacity. That sum of requests includes all containers managed by the kubelet, but excludes any
containers started directly by the container runtime, and also excludes any processes running
outside the kubelet&apos;s control.</p>
<h2 id="node-topology"><a name="node-topology" class="anchor-navigation-ex-anchor" href="#node-topology"><i class="fa fa-link" aria-hidden="true"></i></a>1.6. Node topology</h2>
<p>If you have enabled the <code>TopologyManager</code> feature gate, then the kubelet can use topology hints when
marking resource assignment decisions.</p>
<h2 id="graceful-nodes-shutdown"><a name="graceful-nodes-shutdown" class="anchor-navigation-ex-anchor" href="#graceful-nodes-shutdown"><i class="fa fa-link" aria-hidden="true"></i></a>1.7. Graceful nodes shutdown</h2>
<p>The kubelet attempts to detect node system shutdown and terminates pods running on the node.</p>
<p>Kubelet ensures that pods follow the normal pod termination process during the node shutdown. 
During node shutdown, the kubelet does not accept new Pods (even if these Pods are already
bound to the node).</p>
<p>The Graceful nodes shutdown feature depends on systemd since it takes advantage of systemd inhibitor
locks to delay the node shutdown with a given duration.</p>
<p>Graceful nodes shutdown is controlled with the <code>GracefulNodShutdown</code> feature gate which is enabled
by default in 1.21.</p>
<p>Note that by default, both configuration options described below, <code>shutdownGracePeriod</code> and
<code>shutdownGracePeriodCriticalPods</code> are set to zero, thus not activating the graceful node shutdown
functionality. To activate the feature, the two kubelet config settings should be configured
appropriately and set to non-zero values.</p>
<p>Once systemd detects or notifies node shutdown, the kubelet sets a <code>NotReady</code> condition on the Node,
with the <code>reason</code> set to &quot;node is shutting down&quot;.The kube-scheduler honors this condition and does not
scheduler any Pods onto the affected node; other third-party schedulers are expected to follow the
same login. This means that new Pods won&apos;t be scheduled onto that node and therefore none will start.</p>
<p>The kubelet also rejects Pods during the <code>PodAdmission</code> phase if an ongoing node shutdown ahs been 
detected, so that even Pods with a toleration for <code>node.kubernetes.io/not-ready:NoSchedule</code> do
not start there.</p>
<p>At the same time when kubelet is setting that condition on its Node via the API, the kubelet also
begins terminating any Pods that are running locally.</p>
<p>During a graceful shutdown, kubelet terminates pods in two phases:</p>
<ol>
<li>Terminate regular pods running on the node.</li>
<li>Terminate critical pods running on the node.</li>
</ol>
<p>Graceful node shutdown feature is configured with two <code>kubeletConfiguration</code> options:</p>
<ul>
<li><code>shutdownGracePeriod</code>: Specifies the total duration that the node should delay the shutdown by.
This is the total grace period for pod termination for both regular and critical pods.</li>
<li><code>shutdownGracePeriodCriticalPods</code>: Specifies the duration used to terminate critical pods during
a node shutdown. This value should be less than <code>shutdownGracePeriod</code>.</li>
</ul>
<p>For example, if <code>shutdownGracePeriod=30s</code>, and <code>shutdownGracePeriodCriticalPods=10s</code>, kubelet will
delay the node shutdown be 30 seconds. During the shutdown, the first 20 (30-10) seconds would be
reserved for gracefully terminating normal pods, and the last 10 seconds would be reserved for
terminating critical pods.</p>
<h3 id="pod-priority-based-graceful-nodes-shutdown"><a name="pod-priority-based-graceful-nodes-shutdown" class="anchor-navigation-ex-anchor" href="#pod-priority-based-graceful-nodes-shutdown"><i class="fa fa-link" aria-hidden="true"></i></a>1.7.1. Pod priority based graceful nodes shutdown</h3>
<p>To provide more flexibility during graceful node shutdown around the ordering of pods during shutdown,
graceful nodes shutdown honors the PriorityClass Pods, provided that you enabled this feature in your
cluster. The feature allows cluster administers to explicitly define the ordering of pods during
graceful node shutdown based on priority classes.</p>
<p>The Graceful Node Shutdown feature, as described above, shuts down pods in two phases, non-critical
pods, followed by critical pods. If additional flexibility is needed to explicitly define the
ordering of pods during shutdown in a more granula way, pod priority based graceful shutdown
can be used.</p>
<p>When graceful node shutdown honors pod priorities, this make it possible to do graceful node shutdown
in multiple phases, each phase shutting down a particular priority class of pods. The kubelet can be
configured with the exact phases and shutdown time per phases.</p>
<p>Assuming the following custom pod priority classes in a cluster,</p>
<table>
<thead>
<tr>
<th>Pod priority class name</th>
<th>Pod priority class value</th>
</tr>
</thead>
<tbody>
<tr>
<td>custom-class-a</td>
<td>100000</td>
</tr>
<tr>
<td>custom-class-b</td>
<td>10000</td>
</tr>
<tr>
<td>custom-class-c</td>
<td>1000</td>
</tr>
<tr>
<td>regular/unset</td>
<td>0</td>
</tr>
</tbody>
</table>
<p>Within the kubelet configuration the settings for <code>shutdownGracePeriodByPodPriority</code> could look like:</p>
<table>
<thead>
<tr>
<th>Pod priority class value</th>
<th>Shutdown period</th>
</tr>
</thead>
<tbody>
<tr>
<td>100000</td>
<td>10 seconds</td>
</tr>
<tr>
<td>10000</td>
<td>180 seconds</td>
</tr>
<tr>
<td>1000</td>
<td>120 seconds</td>
</tr>
<tr>
<td>0</td>
<td>60 seconds</td>
</tr>
</tbody>
</table>
<p>The corresponding kubelet config YAML configuration would be:</p>
<pre class="language-"><code class="lang-yaml"><span class="token key atrule">shutdownGracePeriodByPodPriority</span><span class="token punctuation">:</span>
  <span class="token punctuation">-</span> <span class="token key atrule">priority</span><span class="token punctuation">:</span> <span class="token number">100000</span>
    <span class="token key atrule">shutdownGracePeriodSeconds</span><span class="token punctuation">:</span> <span class="token number">10</span>
  <span class="token punctuation">-</span> <span class="token key atrule">priority</span><span class="token punctuation">:</span> <span class="token number">10000</span>
    <span class="token key atrule">shutdownGracePeriodSeconds</span><span class="token punctuation">:</span> <span class="token number">180</span>
  <span class="token punctuation">-</span> <span class="token key atrule">priority</span><span class="token punctuation">:</span> <span class="token number">1000</span>
    <span class="token key atrule">shutdownGracePeriodSeconds</span><span class="token punctuation">:</span> <span class="token number">120</span>
  <span class="token punctuation">-</span> <span class="token key atrule">priority</span><span class="token punctuation">:</span> <span class="token number">0</span>
    <span class="token key atrule">shutdownGracePeriodSeconds</span><span class="token punctuation">:</span> <span class="token number">60</span>
</code></pre>
<p>The above table implies that any pod with <code>priority</code> value&gt;=100000 will get just 10 seconds to stop,
any pod with value&gt;=10000 and <100000 180="" will="" get="" seconds="" to="" stop,="" any="" pod="" with="" value="">=1000 and</100000></p>
<p>&lt;10000 will get 120 seconds to stop. Finally, all other pods will get 60 seconds to stop.</p>
<h2 id="non-graceful-nodes-shutdown-handling"><a name="non-graceful-nodes-shutdown-handling" class="anchor-navigation-ex-anchor" href="#non-graceful-nodes-shutdown-handling"><i class="fa fa-link" aria-hidden="true"></i></a>1.8. Non-graceful nodes shutdown handling</h2>
<p>A node shutdown action may not be detected by kubelet&apos;s Node Shutdown Manager, either because the
command does not trigger the inhibitor locks mechanism used by kubelet or because of a user error,
i.e., the ShutdownGracePeriod and ShutdownGracePeriodCriticalPods are not configured properly.</p>
<p>When a node is shutdown but not detected by kubelet&apos;s Node Shutdown Manager, the pods that are part of
a StatefulSet will be stuck in terminating status on the shutdown node and cannot move to a new
running node. This is because kubelet on the shutdown node is not available to delete the pods so
the StatefulSet cannot create a new pod with the same name. If there are volumes used by the pods,
the VolumeAttachments will not be deleted from the original shutdown nodes so the volumes used by
these pods cannot be attached to a new running node. As a result, the application running on the
StatefulSet cannot function properly. If the original shutdown node comes up, the pods will be
deleted by kubelet and new pods will be created on a different running node. If the original shutdown
node does not come up, these pods will be stuck in terminating status on the shutdown node forever.</p>
<p>To mitigate the above situation, a user can manually add the taint <code>node.kubernetes.io/out-of-service</code>
with either <code>NoExecute</code> or <code>NoSchdule</code> effect to a Node marking it out-of-service. If the
<code>NodeOutOfServiceVolumeDetach</code> feature gate is enabled on kube-controller-manager, and a Node is marked
out-of-service with this taint, the pods on the node will be forcefully deleted if there are no
matching tolerations on it and volume detach operations for the pods terminating on the node will
happen immediately. This allows the Pods on the out-of-service node to recover quickly on a
different node.</p>
<p>During a non-graceful shutdown, Pods are terminated in the two phases:</p>
<ol>
<li>Force delete the Pods that do not have matching <code>out-of-service</code> tolerations.</li>
<li>Immediately perform detach volume operation for such pods.</li>
</ol>
<h2 id="swap-memory-management"><a name="swap-memory-management" class="anchor-navigation-ex-anchor" href="#swap-memory-management"><i class="fa fa-link" aria-hidden="true"></i></a>1.9. Swap memory management</h2>
<p>To enable swap on a node, the <code>NodeSwap</code> feature gate must be enabled on the kubelet, and the
<code>--fail-swap-on</code> command line flag or <code>failSwapOn</code> configuration setting must be set to false.</p>
<p>A user can also optionally configure <code>memorySwap.swapBehavior</code> in order to specify how a node will
use swap memory. For example:</p>
<pre class="language-"><code class="lang-yaml"><span class="token key atrule">memorySwap</span><span class="token punctuation">:</span>
  <span class="token key atrule">swapBehavior</span><span class="token punctuation">:</span> UnlimitedSwap
</code></pre>
<ul>
<li><code>UnlimitedSwap</code> (default): Kubernetes workloads can use as much swap memory as the request, up to
the system limit.</li>
<li><code>LimitedSwap</code>: The utilization of swap memory by Kubernetes workloads is subject to limitations.
Only Pods of burstable QoS are permitted to employ swap.</li>
</ul>
<p>If configuration for <code>memorySwap</code> is not specified and the feature gate is enabled, by default the
kubelet will apply the same behaviour as the <code>UnlimitedSwap</code> setting.</p>
<p>With <code>LimitedSwap</code>, Pods that do not fall under the Burstable QoS classification (i.e. <code>BestEffort</code> /
 <code>Guaranteed</code> Qos Pods) are prohibited from utilizing swap memory. To maintain the aforementioned
security and node health guarantees, these Pods are not permitted to use swap memory when
<code>LimitedSwap</code> is in effect.</p>
<p>Prior to detailing the calculation of the swap limit, it is necessary to define the following terms:</p>
<ul>
<li>nodeTotalMemory: The total amount of physical memory available on the node.</li>
<li>totalPodsSwapAvailable: The total amount of swap memory on the node that is available for use by
Pods (some swap memory may be reserved for system use).</li>
<li>containerMemoryRequest: The container&apos;s memory request</li>
</ul>
<p>Swap limitation is configured as: (containerMemoryRequest / nodeTotalMemory) * totalPodsSwapAvailable.</p>
<p>It is important to note that, for containers within Burstable QoS Pods, it is possible to opt-out of
swap usage by specifying memory requests that are equal to memory limits. Containers configured
in this manner will not have access to swap memory.</p>
<p>Swap is supported only with cgroup v2, cgroup v1 is not supported.</p>
<h2 id="whats-next"><a name="whats-next" class="anchor-navigation-ex-anchor" href="#whats-next"><i class="fa fa-link" aria-hidden="true"></i></a>1.10. What&apos;s next</h2>
<ul>
<li><a href="components.html#node-components">Components</a> that make up a node.</li>
<li><a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.28/#node-v1-core" target="_blank">API definition for Node</a>.</li>
<li>Node section of the architecture design document.</li>
<li>Taints and Tolerations.</li>
<li>Node Resource Managers.</li>
<li>Resource Management for windows nodes.</li>
</ul>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="components.html" class="navigation navigation-prev " aria-label="Previous page: Kubernetes Components">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="../kubernetes.html#tutorial" class="navigation navigation-next " aria-label="Next page: Kubernetes Tutorial">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"Kubernetes Nodes","level":"1.2.1.3","depth":3,"next":{"title":"Kubernetes Tutorial","level":"1.2.2","depth":2,"anchor":"#tutorial","path":"markdown/document/kubernetes/kubernetes.md","ref":"markdown/document/kubernetes/kubernetes.md#tutorial","articles":[{"title":"Kubernetes Basics","level":"1.2.2.1","depth":3,"path":"markdown/document/kubernetes/tutorial/kubernetes-basics.md","ref":"markdown/document/kubernetes/tutorial/kubernetes-basics.md","articles":[]}]},"previous":{"title":"Kubernetes Components","level":"1.2.1.2","depth":3,"path":"markdown/document/kubernetes/concepts/components.md","ref":"markdown/document/kubernetes/concepts/components.md","articles":[]},"dir":"ltr"},"config":{"plugins":["theme-default","prism","-highlight","search-pro","-search","-lunr","expandable-chapters-small","splitter","-sharing","anchor-navigation-ex","code"],"styles":{"ebook":"styles/ebook.css","epub":"styles/epub.css","mobi":"styles/mobi.css","pdf":"styles/pdf.css","print":"styles/print.css","website":"styles/website.css"},"pluginsConfig":{"prism":{},"search-pro":{},"expandable-chapters-small":{},"splitter":{},"anchor-navigation-ex":{"associatedWithSummary":true,"float":{"floatIcon":"fa fa-navicon","level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"mode":"float","multipleH1":true,"pageTop":{"level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"printLog":false,"showGoTop":true,"showLevel":true},"code":{"copyButtons":true},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"showLevel":false,"styles":{"ebook":"styles/ebook.css","epub":"styles/epub.css","mobi":"styles/mobi.css","pdf":"styles/pdf.css","print":"styles/print.css","website":"styles/website.css"}}},"theme":"default","author":"chenjiebin","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pluginConfig":{"prism":{"css":["prismjs/themes/prism-solarizedlight.css"]},"anchor-navigation-ex":{"showLevel":true},"theme-default":{"toggleMenu":false}},"variables":{},"title":"GitBook笔记","gitbook":"*","description":"学习笔记，包含前后端基础知识及框架的学习笔记"},"file":{"path":"markdown/document/kubernetes/concepts/nodes.md","mtime":"2023-12-26T07:30:01.902Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2024-02-28T09:32:04.838Z"},"basePath":"../../../..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../../../../gitbook/gitbook.js"></script>
    <script src="../../../../gitbook/theme.js"></script>
    
        
        <script src="../../../../gitbook/gitbook-plugin-search-pro/jquery.mark.min.js"></script>
        
    
        
        <script src="../../../../gitbook/gitbook-plugin-search-pro/search.js"></script>
        
    
        
        <script src="../../../../gitbook/gitbook-plugin-expandable-chapters-small/expandable-chapters-small.js"></script>
        
    
        
        <script src="../../../../gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="../../../../gitbook/gitbook-plugin-code/plugin.js"></script>
        
    
        
        <script src="../../../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

